﻿/// Copyright (c) Microsoft Corporation.  All rights reserved.
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using System.ComponentModel;
using System.Windows.Forms;

namespace Tcvt.Packages
{
    [Guid(GuidList.guidTfsBuggerVSPackageBuildOptionsString)]
    public class BuildOptions : DialogPage
    {
        private bool _skipLabel = false;
        [Category("Buddy Build Settings")]
        [DisplayName("Skip Labeling Buddy Builds")]
        [DefaultValue(false)]
        [Description("Set to true so that no labeling of the sources is done prior to performing a buddy build.")]
        public bool SkipLabel
        {
            get
            {
                return _skipLabel;
            }
            set
            {
                _skipLabel = value;
            }
        }

        private bool _skipDropBuild = false;
        [Category("Buddy Build Settings")]
        [DisplayName("Skip Build Drop Creation")]
        [DefaultValue(false)]
        [Description("Set to true so that binaries are not copied to the build drop location after a successful build.")]
        public bool SkipDropBuild
        {
            get
            {
                return _skipDropBuild;
            }
            set
            {
                _skipDropBuild = value;
            }
        }

        private bool _skipUpdateWorkitems = false;
        [Category("Buddy Build Settings")]
        [DisplayName("Skip Updating Associated Work Items")]
        [DefaultValue(false)]
        [Description("Set to true so that the associated work items are not updated after a successful build.")]
        public bool SkipUpdateWorkitems
        {
            get
            {
                return _skipUpdateWorkitems;
            }
            set
            {
                _skipUpdateWorkitems = value;
            }
        }

        private string _buddyBuildWebServiceUri = "http://localhost:8020/IntegrationService/BuildService.asmx";
        [Category("Buddy Build Web Service")]
        [DisplayName("Buddy Build Web Service URI")]
        [DefaultValue("")]
        [Description("The buddy build integration web service URI, e.g. http://localhost:8020/IntegrationService/BuildService.asmx.")]
        public string BuddyBuildWebServiceUri
        {
            get
            {
                return _buddyBuildWebServiceUri;
            }
            set
            {
                _buddyBuildWebServiceUri = value;
            }
        }

        private bool _bypassBuddyBuildWebService = true;
        [Category("Buddy Build Web Service")]
        [DisplayName("Bypass Buddy Build Web Service")]
        [DefaultValue(true)]
        [Description("Set to true to skip buddy build requests going through the buddy build web service. " +
            "Typcially, this should be set to false. Setting to true is not recommended unless your account " +
            "already has the 'Administer a Build' permission on the selected build definitions team project " +
            "in addition to the 'Start a Build' permission.")]
        public bool BypassBuddyBuildWebService
        {
            get
            {
                return _bypassBuddyBuildWebService;
            }
            set
            {
                if (value || (!value && this.BuddyBuildWebServiceUri.Length > 0))
                {
                    _bypassBuddyBuildWebService = value;
                }
                else
                {
                    _bypassBuddyBuildWebService = true;
                    Utils.ShowErrorMessageBox("'Buddy Build Web Service URI' is blank. Please enter a value before setting " +
                        "'Bypass Buddy Build Web Service' to false.");
                }
            }
        }

        private bool _usePassThroughForRegularBuilds = true;
        [Category("Buddy Build Web Service")]
        [DisplayName("Use Pass-through for Regular Builds")]
        [DefaultValue(true)]
        [Description("Set to true to skip regular build requests going through the buddy build web service. " +
            "Typcially, this should be set to true unless you TFS admin does not grant you the 'Start a Build' permission.")]
        public bool UsePassThroughForRegularBuilds
        {
            get
            {
                return _usePassThroughForRegularBuilds;
            }
            set
            {
                if (value || (!value && this.BuddyBuildWebServiceUri.Length > 0))
                {
                    _usePassThroughForRegularBuilds = value;
                }
                else
                {
                    _usePassThroughForRegularBuilds = true;
                    Utils.ShowErrorMessageBox("'Buddy Build Web Service URI' is blank. Please enter a value before setting " +
                        "'Use Pass-through for Regular Builds' to false.");
                }
            }
        }

        private bool _showDisabledAgents = false;
        [Category("Build Agents")]
        [DisplayName("Show Disabled Build Agents")]
        [DefaultValue(false)]
        [Description("Set to true so that both disabled and enabled build agents are displayed in the 'Build Agent' drop down.")]
        public bool ShowDisabledAgents
        {
            get
            {
                return _showDisabledAgents;
            }
            set
            {
                _showDisabledAgents = value;
            }
        }

        private bool _showDisabledBuildDefinitions = false;
        [Category("Build Definitions")]
        [DisplayName("Show Disabled Build Definitions")]
        [DefaultValue(false)]
        [Description("Set to true so that both disabled and enabled build definitions are displayed in the 'Build Definition' drop down.")]
        public bool ShowDisabledBuildDefinitions
        {
            get
            {
                return _showDisabledBuildDefinitions;
            }
            set
            {
                _showDisabledBuildDefinitions = value;
            }
        }

        // !!! FOR FUTURE USE !!!
        //private string _defaultAgentPoolOverride = "";
        //[Category("Agent Pool Settings")]
        //[DisplayName("Default Agent Pool OVerride")]
        //[DefaultValue("")]
        //[Description("For future use. Leave empty for the \"Default\" agent pool.")]
        //public string DefaultAgentPoolOverride
        //{
        //    get
        //    {
        //        return _defaultAgentPoolOverride;
        //    }
        //    set
        //    {
        //        _defaultAgentPoolOverride = value;
        //    }
        //}
    }
}
